package com.yshkj.payment.entity;

import com.yshkj.payment.utils.DateUtils;
import com.yshkj.payment.utils.UuidGenerator;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;

/**
 * 基础类
 * 所有其他domain均继承此类
 * Created by 唐旭 on 2016/8/26.
 */
@MappedSuperclass
public abstract class BaseDomain implements Serializable {

    private static final long serialVersionUID = -6794110046849293580L;

    @Id
    protected String uuid = UuidGenerator.generate();

    @Column
    protected Date createDateTime = DateUtils.now();

    @Column
    protected boolean archive = false;

    public BaseDomain() {
    }

    public String getUuid() {
        return uuid;
    }

    @SuppressWarnings("unchecked")
    public <T extends BaseDomain> T setUuid(String uuid) {
        this.uuid = uuid;
        return (T) this;
    }

    public Date getCreateDateTime() {
        return createDateTime;
    }

    @SuppressWarnings("unchecked")
    public <T extends BaseDomain> T setCreateDateTime(Date createDateTime) {
        this.createDateTime = createDateTime;
        return (T) this;
    }

    public boolean isArchive() {
        return archive;
    }

    @SuppressWarnings("unchecked")
    public <T extends BaseDomain> T setArchive(boolean archive) {
        this.archive = archive;
        return (T) this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BaseDomain that = (BaseDomain) o;

        return uuid != null ? uuid.equals(that.uuid) : that.uuid == null;

    }

    @Override
    public int hashCode() {
        return uuid != null ? uuid.hashCode() : 0;
    }
}
